//
//  UIBarButtonItem+ZZCExtension.m
//  ZZC-Finance
//
//  Created by mac on 2017/5/21.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "UIBarButtonItem+ZZCExtension.h"

@implementation UIBarButtonItem (ZZCExtension)
+ (instancetype)backBarButtonWithTarget:(id)target action:(SEL)action {
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [button setTitle:@"返回" forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 0, 50, 30);
    [button setImageEdgeInsets:UIEdgeInsetsMake(7, 0, 7, 42)];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[self alloc] initWithCustomView:button];
}

/**
 *  返回自定义的item
 *
 *  @param name   item的名字
 *  @param target self
 *  @param action sel方法
 *
 *  @return 自定义的itme
 */
+ (instancetype)itemWithName:(NSString *)name target:(id)target action:(SEL)action {
    
    //定义一个button控件
    UIButton *tagBtn = [[UIButton alloc] init];
    tagBtn.layer.cornerRadius = 5.0;
    //设置frame
    tagBtn.frame = CGRectMake(0, 0, 50, 30);
    
    //字体大小
    tagBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [tagBtn setTitle:name forState:UIControlStateNormal];
    [tagBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //    [tagBtn setBackgroundImage:[UIImage imageNamed:@"agree-a"] forState:UIControlStateNormal];
    [tagBtn setBackgroundColor:[UIColor clearColor]];
    //    [tagBtn setBackgroundImage:[UIImage imageNamed:@"agree-b"] forState:UIControlStateSelected];
    
    //按钮背景色
    //    tagBtn.backgroundColor = [UIColor whiteColor];
    
    //添加点击事件
    [tagBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc] initWithCustomView:tagBtn];
}

+ (instancetype)itemWithImage:(NSString *)image higghtImage:(NSString *)higghtImage target:(id)target cation:(SEL)cation {
    //定义一个button控件
    UIButton *tagBtn = [[UIButton alloc] init];
    tagBtn.layer.cornerRadius = 6.0;
    //设置frame
    tagBtn.frame = CGRectMake(0, 0, 24, 26);
    
    //字体大小
    tagBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [tagBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tagBtn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [tagBtn setBackgroundImage:[UIImage imageNamed:higghtImage] forState:UIControlStateSelected];
    //按钮背景色
    //    tagBtn.backgroundColor = [UIColor whiteColor];
    
    //添加点击事件
    [tagBtn addTarget:target action:cation forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc] initWithCustomView:tagBtn];
}
@end
